/*
 * Copyright (c) 2018 LingoChamp Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.liulishuo.okdownload.sample.util.task_list

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.SeekBar
import android.widget.TextView
import com.liulishuo.okdownload.sample.R
import com.liulishuo.okdownload.sample.util.task_list.ListTaskAdapter.TaskViewHolder

class ListTaskAdapter(val constroller: TaskConstroller) : RecyclerView.Adapter<TaskViewHolder>() {

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): TaskViewHolder {
        return TaskViewHolder(
            LayoutInflater.from(p0.context)
                .inflate(R.layout.item_task, p0, false)
        )
    }

    override fun onBindViewHolder(p0: TaskViewHolder, p1: Int) {
        constroller.bind(p0, p1)
    }

    override fun getItemCount(): Int = constroller.size()

    class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) {
        var nameTv: TextView = v.findViewById(R.id.nameTv)
        var priorityTv: TextView = v.findViewById(R.id.priorityTv)
        var prioritySb: SeekBar = v.findViewById(R.id.prioritySb)
        var statusTv: TextView = v.findViewById(R.id.statusTv)
        var progressBar: ProgressBar = v.findViewById(R.id.progressBar)
        var stateBtn: ImageView = v.findViewById(R.id.state_btn)
    }

}